package com.comum.javahomework420242025.controller;


import com.comum.javahomework420242025.pojo.*;
import com.comum.javahomework420242025.repository.TraceUserRepository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class TraceUserController {


    @Autowired
    private TraceUserRepository traceUserRepository;

    @PostMapping("/addTraceUser")
    public Result addTraceUser(@RequestBody Traceuser traceUser){


        traceUserRepository.save(traceUser);
        return Result.success();
    }
    @PutMapping("/updateTraceUser")
    public Result updateTraceUser(@RequestBody Traceuser traceUser){
        traceUserRepository.save(traceUser);
        return Result.success();
    }
    @DeleteMapping("/deleteTraceUser")
    public Result deleteTraceUser(String id){
        System.out.println(id);
        return Result.success();
    }





    @GetMapping("/getAllTraceUser")
    public Result getAllTraceUser()
    {
        return Result.success(traceUserRepository.findAll());
    }



    @PostMapping("/getAllChanceByUserId")
    public Result getAllChanceByUserId(@RequestBody AskList askList) {

        String str = askList.getStr();

        List<Chance> chances = traceUserRepository.getAllChanceByUserId(str);


        return Result.success(chances);
    }




}
